// src/characters/enemies/StatueEnemy.cpp
#include "characters/enemies/StatueEnemy.hh"
#include "characters/enemies/Enemy.hh"

#include <iostream>
#include <string>
#include <algorithm>


StatueEnemy::StatueEnemy()
    : Enemy("Stone Statue",                                              
            "A statue that has awakened due to the curse in the campus", 
            500,                                                         // Health
            500,                                                         // Max Health
            150,                                                          // Attack
            80)                                                         // Defense
{
    std::cout << "The " << getName() << " grinds to life!" << std::endl;
}



bool StatueEnemy::attack(ICharacter &target) 
{
    if (!isAlive())
        return false;

    std::cout << getName() << " slams its stony fist towards " << target.getName() << "!" << std::endl;

    unsigned damageDealt = getAttackPower();
    bool targetSurvived = target.takeDamage(damageDealt);

    if (!targetSurvived)
    {
        std::cout << target.getName() << " was crushed by the " << getName() << "!" << std::endl;
    }
    return targetSurvived;
}

bool StatueEnemy::takeDamage(unsigned damage)
{
    unsigned healthBefore = getHealth();
    bool alive = Character::takeDamage(damage);

    if (healthBefore > getHealth())
    { 
        std::cout << "Stone chips fly from the " << getName() << "!" << std::endl;
        if (alive && canBeFinishedByFlashlight())
        {
            std::cout << "The " << getName() << " looks heavily damaged and vulnerable!" << std::endl;
        }
    }
    else if (damage > 0)
    {
        std::cout << "The attack barely scratches the " << getName() << "'s surface." << std::endl;
    }

    if (!alive)
    {
        std::cout << "The " << getName() << " finally stops moving." << std::endl;

    }
    return alive;
}

bool StatueEnemy::canBeFinishedByFlashlight() const
{
    return isAlive() && (getHealth() < FLASHLIGHT_KILL_THRESHOLD);
}